const tabs = {
  state: {
    //   当前激活菜单
    editableTabsValue: "",
    editableTabs: [
      {
        title: "用户管理",
        name: "user",
      },
    ],
  },
  mutations: {
    // 获取tabs
    getTabs(state) {
      const tabs = sessionStorage.getItem("tabsList");
      if (tabs) {
        state.editableTabs = JSON.parse(tabs);
      }
    },
    //   菜单点击事件
    clickMenu(state, val) {
      let res = state.editableTabs.findIndex((item) => item.name === val.name);
      if (res === -1) {
        let tabs = {};
        tabs.title = val.label;
        tabs.name = val.name;
        state.editableTabs.push(tabs);
      }
      // 3.设置当前选中的选项卡
      state.editableTabsValue = val.name;
      // 4.把选中的选项卡存放到session里面
      sessionStorage.setItem("tabsList", JSON.stringify(state.editableTabs));
    },
    // 设置当前激活的选项卡
    setActiveTabs(state, val) {
      state.editableTabsValue = val;
    },
  },
  actions: {},
};
export default tabs;
